package com.cfgj.service.impl;

import com.cfgj.entity.User;
import com.cfgj.entity.UserInfo;
import com.cfgj.entity.Vo.UpdateUser;
import com.cfgj.entity.Vo.UserVo;
import com.cfgj.mapper.UserMapper;
import com.cfgj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    private static Integer CURRENT_PAGE=1;
    private static Integer PAGE_SIZE=5;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserVo> findUserbyStatus(Integer page, Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        return userMapper.findUserbyStatus((CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
    }

    @Override
    public Integer findcount() {
        return userMapper.findcount();
    }

    @Override
    public void updateUserStatus(Integer id, Integer status) {
        UpdateUser user = new UpdateUser();
        user.setId(id);
        user.setStatus(status);
        userMapper.updateUserStatus(user);
    }

    @Override
    public List<UserInfo> accUserbyStatus(Integer page, Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        return userMapper.accUserbyStatus((CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
    }

    @Override
    public Integer usercount() {
        return userMapper.usercount();
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        UserInfo user = new UserInfo();
        user.setId(id);
        user.setStatus(status);
        userMapper.updateStatus(user);
    }
}
